//
//  TableHeaderView.m
//  Study1
//
//  Created by ChenJie on 2/10/20.
//  Copyright © 2020 OrgName. All rights reserved.
//

#import "TableHeaderView.h"

@interface TableHeaderView ()

@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UILabel *label;

@end

@implementation TableHeaderView

#pragma mark - Lifecycle methods

//+ (void)load {
/// Do not keep an empty +load method
//}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor redColor];
        
//        [self addSubview:self.button];
        [self addSubview:self.label];
    }
    return self;
}

- (void)willMoveToSuperview:(UIView *)newSuperview {
    [super willMoveToSuperview:newSuperview];
}

- (void)didMoveToSuperview {
    [super didMoveToSuperview];
}

- (void)willMoveToWindow:(UIWindow *)newWindow {
    [super willMoveToWindow:newWindow];
}

- (void)didMoveToWindow {
    [super didMoveToWindow];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    //
//    self.button.frame = self.bounds;
    self.label.frame = self.bounds;
}

#pragma mark - Public methods



#pragma mark - Private methods



#pragma mark - Event response methods

- (void)buttonDidiClick:(UIButton *)button {
    NSLog(@"do it..");
}

#pragma mark - Delegate methods



#pragma mark - Setter



#pragma mark - Getter

- (UIButton *)button {
    if (!_button) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        
        //
        button.backgroundColor = [UIColor grayColor];
//        button.tag = ButtonTag_button1;
        
        //
        [button setTitle:@"Button" forState:UIControlStateNormal];
        [button setTitle:@"Button highLight" forState:UIControlStateHighlighted];
        [button setTitle:@"Button Selected" forState:UIControlStateSelected];
        
        //
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
        [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateSelected];
        
        // target-action
        [button addTarget:self
                   action:@selector(buttonDidiClick:)
         forControlEvents:UIControlEventTouchUpInside];
        
        _button  = button;
    }
    return _button;
}

- (UILabel *)label {
    if (!_label) {
        UILabel *label = [UILabel new];
        label.text = @"Table Header";
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:20];
        
        _label = label;
    }
    return _label;
}

#pragma mark - Memory management methods

- (void)dealloc {
}

@end
